package com.leyou.search.web;

import com.leyou.common.vo.PageResult;
import com.leyou.search.dto.GoodsDTO;
import com.leyou.search.dto.SearchRequest;
import com.leyou.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 处理请求和响应的方法
 *
 * @version V1.0
 * @package com.leyou.search.web
 * @description:
 * @author: pc
 * @date: 2019/7/2 16:13
 */

@RestController
public class SearchController {
    @Autowired
    private SearchService searchService;

    @PostMapping("page")
    public ResponseEntity<PageResult<GoodsDTO>> search(@RequestBody SearchRequest request) {
       PageResult<GoodsDTO> result = searchService.search(request);
       return ResponseEntity.ok(result);
    }

    @PostMapping("filter")
    public ResponseEntity<Map<String, List<?>>> searchFliters(@RequestBody SearchRequest request) {
        Map<String, List<?>> result = searchService.searchFliters(request);
        return ResponseEntity.ok(result);
    }


}
